##### Replication code for "Framing Police Violence: Repression, Reform, and the Power of History in Chile" #####
#install.packages(c("readr","stringr","scales","texreg","arm","margins")) #If packages not yet installed
#Load packages
library(readr)
library(stringr)
library(scales)
library(texreg)
library(arm)
library(margins)

#Load data (alter file path as needed)
chiledata <- read_csv("analysis_data.csv")

#Delete rows of labels
chiledata <- chiledata[-c(1:2),]

################
#Clean variables
################

#Historical framing treatment: 0 = control; 1 = low dose; 2 = high dose
chiledata$frame <- NA
chiledata$frame[chiledata$Block1_DO == "Q3|Q6|Q7|Q8"] <- 0
chiledata$frame[chiledata$Block1_DO == "Q4|Q6|Q7|Q8"] <- 1
chiledata$frame[chiledata$Block1_DO == "Q38|Q6|Q7|Q8"] <- 2

#Support protester demands: 5 = strongest support; 1 = strongest opposition
chiledata$support_protests <- NA
chiledata$support_protests[chiledata$Q6 == "Apoyo fuerte"] <- 5
chiledata$support_protests[chiledata$Q6 == "Apoyo limitado"] <- 4
chiledata$support_protests[chiledata$Q6 == "Ni apoyo ni oposición"] <- 3
chiledata$support_protests[chiledata$Q6 == "Oposición limitada"] <- 2
chiledata$support_protests[chiledata$Q6 == "Oposición fuerte"] <- 1

#How have your opinions on the protests changed since the protests ended?: 2 = improved; 1 = worsened; 0 = no change
chiledata$change_support <- NA
chiledata$change_support[chiledata$Q7 == "Mejorado"] <- 2
chiledata$change_support[chiledata$Q7 == "Empeorado"] <- 1
chiledata$change_support[chiledata$Q7 == "Ningunos cambios"] <- 0

#How effective do you think the protests will be?: 0 = least effective; 7 = most effective
chiledata$effective <- as.numeric(chiledata$Q8)

#Donation to Comisión Chilena de Derechos Humanos (to reform police violence) and Fundación Superación de la Pobreza (to reduce inequality)
chiledata$donate_polviolence <- as.numeric(chiledata$Q40) #Donation to reform police violence
chiledata$donate_ineq <- as.numeric(chiledata$Q42) #Donation to reduce inequality

#Count words (strings) in letter to a delegate
chiledata$strings <- as.integer(NA)
#Removing responses that simply say "no"
chiledata$letter <- chiledata$Q16
chiledata$letter[chiledata$Q16 == "No" | chiledata$Q16 == "no" | chiledata$Q16 == "Ninguno" | chiledata$Q16 == "ninguno"] <- NA
for (i in 1:nrow(chiledata)) 
{
  chiledata$strings[i]    = str_count(chiledata$letter[i], '\\S+') # counts the strings
}

#Letter content
chiledata$text_econ_proreform <- NA
chiledata$text_econ_proreform[chiledata$`Economic issues (pro-reform/anti-inequality/pro-social services)` == 1] <- 1
chiledata$text_econ_proreform[chiledata$`Economic issues (pro-reform/anti-inequality/pro-social services)` == 0] <- 0
chiledata$text_stateviolence_proreform <- NA
chiledata$text_stateviolence_proreform[chiledata$`State violence/police (pro-reform and human rights)` == 1] <- 1
chiledata$text_stateviolence_proreform[chiledata$`State violence/police (pro-reform and human rights)` == 0] <- 0

#Did you participate in the protests of 19-20?: 1 = yes; 0 = no
chiledata$protestpart <- NA
chiledata$protestpart[chiledata$Q16_1 == "Sí"] <- 1
chiledata$protestpart[chiledata$Q16_1 == "No"] <- 0

#Which candidate list would you vote for if the election were next Sunday?: 1 = Apruebo Dignidad; 2 = Apruebo; 3 = Vamos por Chile; 0 = other; 99 = don't know
chiledata$votechoice <- NA
chiledata$votechoice[chiledata$Q17 == "Apruebo Dignidad (Frente Amplio, Federación Regionalista Verde Social, Partido Comunista, Revolución Democrática, Convergencia Social, etc.)"] <- 1
chiledata$votechoice[chiledata$Q17 == "La lista del Apruebo (PPD, PS, PR, DC, PRO, etc.)"] <- 2
chiledata$votechoice[chiledata$Q17 == "No sé"] <- 99
chiledata$votechoice[chiledata$Q17 == "Otra lista u otro partido (por favor especifique)"] <- 0
chiledata$votechoice[chiledata$Q17 == "Vamos por Chile (Chile Vamos-UDI, RN, Evópoli, PRI, y Partido Republicano)"] <- 3

#Respondent age
chiledata$age <- 2021 - as.numeric(chiledata$Q19_1)

#Age brackets for comparing sample to national pop
chiledata$age_bracket <- NA
chiledata$age_bracket[chiledata$age < 30] <- 1
chiledata$age_bracket[chiledata$age < 40 & chiledata$age > 29] <- 2
chiledata$age_bracket[chiledata$age < 50 & chiledata$age > 39] <- 3
chiledata$age_bracket[chiledata$age < 60 & chiledata$age > 49] <- 4
chiledata$age_bracket[chiledata$age < 70 & chiledata$age > 59] <- 5
chiledata$age_bracket[chiledata$age > 69] <- 6

#Did you participate in any protests against the military dictatorship?: 0 = no; 1 = yes; 98 = don't remember; 99 = not applicable
chiledata$protest_dictatorship <- NA
chiledata$protest_dictatorship[chiledata$Q21 == "No"] <- 0
chiledata$protest_dictatorship[chiledata$Q21 == "Sí"] <- 1
chiledata$protest_dictatorship[chiledata$Q21 == "No recuerdo"] <- 98
chiledata$protest_dictatorship[chiledata$Q21 == "No se aplica a mí"] <- 99
#Dummy for "Yes" responses
chiledata$protest_dictatorship_yes <- NA
chiledata$protest_dictatorship_yes[chiledata$protest_dictatorship == 1] <- 1
chiledata$protest_dictatorship_yes[chiledata$protest_dictatorship == 0 | chiledata$protest_dictatorship > 1] <- 0

#What year did the Jornadas de Protesta Nacional begin?: 1 = correct; 0 = incorrect
chiledata$jornadas <- NA
chiledata$jornadas[chiledata$Q22_1 == 1973] <- 0
chiledata$jornadas[chiledata$Q22_1 == 1978] <- 0
chiledata$jornadas[chiledata$Q22_1 == 1983] <- 1
chiledata$jornadas[chiledata$Q22_1 == 1988] <- 0
chiledata$jornadas[chiledata$Q22_1 == "No sé"] <- 98
#Dummy for correct response
chiledata$jornadas_dum <- NA
chiledata$jornadas_dum[chiledata$jornadas == 1] <- 1
chiledata$jornadas_dum[chiledata$jornadas != 1] <- 0

#Who was the victim of a violent attack from security forces during the military dictatorship?: 1 = correct; 0 = incorrect
chiledata$victim <- NA
chiledata$victim[chiledata$Q22_2 == "Genaro Arriagada Herrera"] <- 0
chiledata$victim[chiledata$Q22_2 == "No sé"] <- 0
chiledata$victim[chiledata$Q22_2 == "Patricio Aylwin Azócar"] <- 0
chiledata$victim[chiledata$Q22_2 == "Rodrigo Rojas de Negri"] <- 1
chiledata$victim[chiledata$Q22_2 == "Victor Pey Casado"] <- 0

#How did you learn about the protests against the military dictatorship?
#Split up the string in Q23, which contains multiple possible answers per respondent.
split <- strsplit(chiledata$Q23, ",", fixed = TRUE)
chiledata$howlearned1 <- sapply(split, "[", 1)
chiledata$howlearned2 <- sapply(split, "[", 2)
chiledata$howlearned3 <- sapply(split, "[", 3)
chiledata$howlearned4 <- sapply(split, "[", 4)
chiledata$howlearned5 <- sapply(split, "[", 5)
#Now create variables indicating whether a respondent mentioned a given info source.
#To code whether respondent learned from friends and family, first assign zeros to any respondent who mentioned at least one info source.
chiledata$howlearned_friendsfam <- NA
chiledata$howlearned_friendsfam[!is.na(chiledata$howlearned1)] <- 0
#Next, recode as 1 people who mentioned friends and fam as one of their info sources.
chiledata$howlearned_friendsfam[chiledata$howlearned1 == "De familiares o amigos" | chiledata$howlearned2 == "De familiares o amigos" | chiledata$howlearned3 == "De familiares o amigos" | chiledata$howlearned4 == "De familiares o amigos" | chiledata$howlearned5 == "De familiares o amigos"] <- 1
#Repeat for other info sources.
chiledata$howlearned_media <- NA
chiledata$howlearned_media[!is.na(chiledata$howlearned1)] <- 0
chiledata$howlearned_media[chiledata$howlearned1 == "De medios o libros" | chiledata$howlearned2 == "De medios o libros" | chiledata$howlearned3 == "De medios o libros" | chiledata$howlearned4 == "De medios o libros" | chiledata$howlearned5 == "De medios o libros"] <- 1
chiledata$howlearned_school <- NA
chiledata$howlearned_school[!is.na(chiledata$howlearned1)] <- 0
chiledata$howlearned_school[chiledata$howlearned1 == "En la escuela" | chiledata$howlearned2 == "En la escuela" | chiledata$howlearned3 == "En la escuela" | chiledata$howlearned4 == "En la escuela" | chiledata$howlearned5 == "En la escuela"] <- 1
chiledata$howlearned_experience <- NA
chiledata$howlearned_experience[!is.na(chiledata$howlearned1)] <- 0
chiledata$howlearned_experience[chiledata$howlearned1 == "Experiencia de primera mano" | chiledata$howlearned2 == "Experiencia de primera mano" | chiledata$howlearned3 == "Experiencia de primera mano" | chiledata$howlearned4 == "Experiencia de primera mano" | chiledata$howlearned5 == "Experiencia de primera mano"] <- 1 
chiledata$howlearned_other <- NA
chiledata$howlearned_other[!is.na(chiledata$howlearned1)] <- 0
chiledata$howlearned_other[chiledata$howlearned1 == "Otro (por favor especifique)" | chiledata$howlearned2 == "Otro (por favor especifique)" | chiledata$howlearned3 == "Otro (por favor especifique)" | chiledata$howlearned4 == "Otro (por favor especifique)" | chiledata$howlearned5 == "Otro (por favor especifique)"] <- 1
#There are now five dummies: howlearned_friendsfam, howlearned_media, howlearned_school, howlearned_experience, howlearned_other

#Left-right ideological self placement
chiledata$ideology <- NA
chiledata$ideology <- as.numeric(chiledata$Q24)

#Respondent gender: male = 1; non-male = 0. Grouping female and other as non-male.
chiledata$male <- NA
chiledata$male[chiledata$Q44 == "Hombre"] <- 1
chiledata$male[chiledata$Q44 == "Mujer"] <- 0
chiledata$male[chiledata$Q44 == "Otro"] <- 0

#Respondent race/ethnicity: white = 1; mestizo/a or other = 0
chiledata$white <- NA
chiledata$white[chiledata$Q25 == "Asiático(a)"] <- 0
chiledata$white[chiledata$Q25 == "Blanco(a)"] <- 1
chiledata$white[chiledata$Q25 == "Indígena"] <- 0
chiledata$white[chiledata$Q25 == "Mestizo(a)"] <- 0
chiledata$white[chiledata$Q25 == "Mulato(a)"] <- 0
chiledata$white[chiledata$Q25 == "Negro(a)"] <- 0
chiledata$white[chiledata$Q25 == "Otra raza"] <- 0

#Respondent education: 1 = lowest (basic); 5 = highest (postgrad)
chiledata$educ <- NA
chiledata$educ[chiledata$Q26 == "Básica"] <- 1
chiledata$educ[chiledata$Q26 == "Media incompleta"] <- 2
chiledata$educ[chiledata$Q26 == "Media completa"] <- 3
chiledata$educ[chiledata$Q26 == "Superior incompleta"] <- 4
chiledata$educ[chiledata$Q26 == "Título técnico superior o profesional"] <- 5
chiledata$educ[chiledata$Q26 == "Universitario (licenciatura)"] <- 6
chiledata$educ[chiledata$Q26 == "Postgrado"] <- 7

#Respondent income: 1 = lowest bracket; 11 = highest bracket
chiledata$income <- NA
chiledata$income[chiledata$Q45_1 == "0 - 250.000"] <- 1
chiledata$income[chiledata$Q45_1 == "250.000 - 500.000"] <- 2
chiledata$income[chiledata$Q45_1 == "500.000 - 750.000"] <- 3
chiledata$income[chiledata$Q45_1 == "750.000 - 1.000.000"] <- 4
chiledata$income[chiledata$Q45_1 == "1.000.000 - 1.250.000"] <- 5
chiledata$income[chiledata$Q45_1 == "1.250.000 - 1.500.000"] <- 6
chiledata$income[chiledata$Q45_1 == "1.500.000 - 1.750.000"] <- 7
chiledata$income[chiledata$Q45_1 == "1.750.000 - 2.000.000"] <- 8
chiledata$income[chiledata$Q45_1 == "2.000.000 - 2.250.000"] <- 9
chiledata$income[chiledata$Q45_1 == "2.250.000 - 2.500.000"] <- 10
chiledata$income[chiledata$Q45_1 == "Más de 2.500.000"] <- 11

#Respondent religiosity: 1 = lowest; 7 = highest
chiledata$relig <- NA
chiledata$relig[chiledata$Q27 == "Nunca, prácticamente nunca"] <- 1
chiledata$relig[chiledata$Q27 == "Con menor frecuencia"] <- 2
chiledata$relig[chiledata$Q27 == "Una vez al año"] <- 3
chiledata$relig[chiledata$Q27 == "Solo en días festivos especiales"] <- 4
chiledata$relig[chiledata$Q27 == "Una vez al mes"] <- 5
chiledata$relig[chiledata$Q27 == "Una vez por semana"] <- 6
chiledata$relig[chiledata$Q27 == "Más de una vez por semana"] <- 7

#Urban: 1 = urban; 0 = rural or other
chiledata$urban <- NA
chiledata$urban[chiledata$Q28 == "Urbano"] <- 1
chiledata$urban[chiledata$Q28 == "Rural"] <- 0
chiledata$urban[chiledata$Q28 == "Otro"] <- 0

#Region
chiledata$region <- as.factor(chiledata$Q43_1)

##################
#Hypothesis tests 
##################

### Rescaling vars for easier visualization of results
chiledata$support_protests.r <- rescale(chiledata$support_protests)
chiledata$effective.r <- rescale(chiledata$effective)
chiledata$donate_ineq.r <- rescale(chiledata$donate_ineq)
chiledata$donate_polviolence.r <- rescale(chiledata$donate_polviolence)
chiledata$strings.r <- rescale(chiledata$strings)

###DV = support of protester demands
mod_support.r <- lm(support_protests.r ~ as.factor(frame), data = chiledata)

###DV = perceived protester effectiveness
mod_effective.r <- lm(effective.r ~ as.factor(frame), data = chiledata)

###DV = donations to orgs focusing on a) reducing inequality; or b) reforming police violence
mod_donate_ineq.r <- lm(donate_ineq.r ~ as.factor(frame), data = chiledata)
mod_donate_polviolence.r <- lm(donate_polviolence.r ~ as.factor(frame), data = chiledata)

###DV = words written to delegate
mod_strings.r <- lm(strings.r ~ as.factor(frame), data = chiledata)

#########################
#Main effects plots
#########################
names <- c("Intercept","Low Dose","High Dose")
x.scale <- c(-.15,.15)

#Figure 2.A: Attitudinal Outcomes
coefplot(mod_support.r, xlim = x.scale, varnames = names, pch.pts = 16, cex.pts = 1.5, main = "Treatment Effect")
coefplot(mod_effective.r, xlim = x.scale, add = TRUE, pch.pts = 17, cex.pts = 1.5)
legend("bottomleft", legend = c("Support of Protester Demands","Perceived Effectiveness of Protests"), pch = c(16, 17), lty=1, cex=1, box.lty = 0)
if(!is.null(dev.list())) dev.off()

#Figure 2.B: Quasi-Behavioral Outcomes
coefplot(mod_donate_ineq.r, xlim = x.scale, varnames = names, pch.pts = 16, cex.pts = 1.5, main = "Treatment Effect")
coefplot(mod_donate_polviolence.r, xlim = x.scale, varnames = names, pch.pts = 17, cex.pts = 1.5, add = TRUE)
coefplot(mod_strings.r, xlim = x.scale, varnames = names, pch.pts = 4, cex.pts = 1.5, add = TRUE, offset = 0.2)
legend("bottomleft", legend = c("Donation to Reduce Inequality","Donation to Reform Police Violence","Words Written to Delegate"), pch = c(16, 17, 4), lty=1, cex=1, box.lty = 0)
if(!is.null(dev.list())) dev.off()

#############################
#Interaction effects plots
############################

###Subset data by treatment level, then regress donations on ideology or age for each treatment level
chiledata_control <- subset(chiledata, frame == 0)
chiledata_lowdose <- subset(chiledata, frame == 1)
chiledata_highdose <- subset(chiledata, frame == 2)
#Ideology interactions
mod_donate_polviolence_ideo_control <- lm(donate_polviolence ~ ideology, data = chiledata_control)
mod_donate_polviolence_ideo_lowdose <- lm(donate_polviolence ~ ideology, data = chiledata_lowdose)
mod_donate_polviolence_ideo_highdose <- lm(donate_polviolence ~ ideology, data = chiledata_highdose)
#Age interactions
mod_donate_polviolence_age_control <- lm(donate_polviolence ~ age, data = chiledata_control)
mod_donate_polviolence_age_lowdose <- lm(donate_polviolence ~ age, data = chiledata_lowdose)
mod_donate_polviolence_age_highdose <- lm(donate_polviolence ~ age, data = chiledata_highdose)

###Plot predicted donations using models above
#Figure 3: Average Treatment Effects of Historical Framing on the Relationship Between Ideology and Donation (in Pesos) to Reform Police Violence
line = 1
cex = 1
side = 3
adj=0
par(mfrow=c(1,3))
plot_donatepolice_control_ideo <- cplot(mod_donate_polviolence_ideo_control, "ideology", what = "prediction", xlab = "Ideology", ylab = "Predicted Donation", rug = FALSE, ylim = c(1500, 15500))
mtext("Control", side=side, line=line, cex=cex, adj=adj)
plot_donatepolice_lowdose_ideo <- cplot(mod_donate_polviolence_ideo_lowdose, "ideology", what = "prediction", xlab = "Ideology", ylab = "Predicted Donation", rug = FALSE, ylim = c(1500, 15500))
mtext("Low Dose", side=side, line=line, cex=cex, adj=adj)
plot_donatepolice_highdose_ideo <- cplot(mod_donate_polviolence_ideo_highdose, "ideology", what = "prediction", xlab = "Ideology", ylab = "Predicted Donation", rug = FALSE, ylim = c(1500, 15500))
mtext("High Dose", side=side, line=line, cex=cex, adj=adj)
if(!is.null(dev.list())) dev.off()

#Figure 4: Average Treatment Effects of Historical Framing on the Relationship between Age and Donation (in Pesos) to Reform Police Violence
line = 1
cex = 1
side = 3
adj=0
par(mfrow=c(1,3))
plot_donatepolice_control_age <- cplot(mod_donate_polviolence_age_control, "age", what = "prediction", xlab = "Age", ylab = "Predicted Donation", rug = FALSE, ylim = c(-1000,15000))
mtext("Control", side=side, line=line, cex=cex, adj=adj)
plot_donatepolice_lowdose_age <- cplot(mod_donate_polviolence_age_lowdose, "age", what = "prediction", xlab = "Age", ylab = "Predicted Donation", rug = FALSE, ylim = c(-1000,15000))
mtext("Low Dose", side=side, line=line, cex=cex, adj=adj)
plot_donatepolice_highdose_age <- cplot(mod_donate_polviolence_age_highdose, "age", what = "prediction", xlab = "Age", ylab = "Predicted Donation", rug = FALSE, ylim = c(-1000,15000))
mtext("High Dose", side=side, line=line, cex=cex, adj=adj)
if(!is.null(dev.list())) dev.off()

###################
#Testing mechanisms
###################

#Table 1: Older Chileans Are More Likely than Younger Chileans to Have Protested Against the Military Dictatorship and to Be Knowledgeable about the Dictatorship
mod_protest_dictatorship_yes_age <- glm(protest_dictatorship_yes ~ age  + ideology + income + educ + male, family = "binomial", data = chiledata)
mod_jornadasdum_age <- glm(jornadas_dum ~ age  + ideology + income + educ + male + protest_dictatorship_yes, family = "binomial", data = chiledata)
mod_victim_age <- glm(victim ~ age  + ideology + income + educ + male + protest_dictatorship_yes, family = "binomial", data = chiledata)

screenreg(list(mod_protest_dictatorship_yes_age,mod_jornadasdum_age,mod_victim_age),
       custom.model.names = c("Protested Against Military Dictatorship","Knew Year of Jornadas","Knew Negri as Victim"),
       custom.coef.names = c("Intercept","Age","Ideology","Income","Education","Male","Protested Pinochet")
)

#Table 2: Older Chileans Are More Likely than Younger Chileans to Learn about the Military Dictatorship from Experience, and Less Likely to Learn about it by Other Means
mod_howlearned_experience_age <- glm(howlearned_experience ~ age + ideology + income + educ + male, family = "binomial", data = chiledata)
mod_howlearned_friendsfam_age <- glm(howlearned_friendsfam ~ age + ideology + income + educ + male, family = "binomial", data = chiledata)
mod_howlearned_school_age <- glm(howlearned_school ~ age + ideology + income + educ + male, family = "binomial", data = chiledata)
mod_howlearned_media_age <- glm(howlearned_media ~ age  + ideology + income + educ + male, family = "binomial", data = chiledata)

screenreg(list(mod_howlearned_experience_age,mod_howlearned_friendsfam_age,mod_howlearned_school_age,mod_howlearned_media_age),
       custom.model.names = c("Learned from Experience","Learned from Friends/Fam","Learned at School","Learned from Media"),
       custom.coef.names = c("Intercept","Age","Ideology","Income","Education","Male")
)

##################################
#Appendix replication
##################################

#### Appendix A: Sample Details ####
# Code below reproduces sample percents in Table A.1: National Representativeness of Experimental Sample
prop.table(table(chiledata$male)) #1 = male
prop.table(table(chiledata$age_bracket)) #1 = 18-29; 2 = 30-39; 3 = 40-49; 4 = 50-59; 5 = 60-69; 6 = 70+ 
prop.table(table(chiledata$region))
prop.table(table(chiledata$income)) #1 = lowest (0-250,000); 11 = highest (2,250,000+)

#### Appendix B: Balance Tests ####
balance <- polr(as.factor(frame) ~ age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata)
#Table B.1: Relationship between Treatment Status and Covariates
screenreg(balance,
       custom.coef.names = c("Age","White","Education","Income","Religiosity","Party Preference","Urban","Changed Support for Protesters","Cut1","Cut2")
)

#### Appendix C: Full Regressions With and Without Controls ####
###DV = support of protester demands
#Main effects
mod_support <- lm(support_protests ~ as.factor(frame), data = chiledata)
mod_support_controls <- lm(support_protests ~ as.factor(frame) + age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata)
#Interacting treatment with age
mod_support_age <- lm(support_protests ~ as.factor(frame)*age, data = chiledata)
mod_support_age_controls <- lm(support_protests ~ as.factor(frame)*age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata)
#Interacting treatment with ideology
mod_support_ideo <- lm(support_protests ~ as.factor(frame)*ideology, data = chiledata)
mod_support_ideo_controls <- lm(support_protests ~ as.factor(frame)*ideology + age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata)

###DV = perceived protester effectiveness
#Main effects
mod_effective <- lm(effective ~ as.factor(frame), data = chiledata)
mod_effective_controls <- lm(effective ~ as.factor(frame) + age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata)
#Interacting treatment with age
mod_effective_age <- lm(effective ~ as.factor(frame)*age, data = chiledata)
mod_effective_age_controls <- lm(effective ~ as.factor(frame)*age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata)
#Interacting treatment with ideology
mod_effective_ideo <- lm(effective ~ as.factor(frame)*ideology, data = chiledata)
mod_effective_ideo_controls <- lm(effective ~ as.factor(frame)*ideology + age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata)

###DV = donations to orgs focusing on a) reducing inequality; or b) reforming police violence
#Main effects
mod_donate_ineq <- lm(donate_ineq ~ as.factor(frame), data = chiledata)
mod_donate_ineq_controls <- lm(donate_ineq ~ as.factor(frame) + age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata)
mod_donate_polviolence <- lm(donate_polviolence ~ as.factor(frame), data = chiledata)
mod_donate_polviolence_controls <- lm(donate_polviolence ~ as.factor(frame) + age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata)
#Interacting treatment with age
mod_donate_ineq_age <- lm(donate_ineq ~ as.factor(frame)*age, data = chiledata)
mod_donate_ineq_age_controls <- lm(donate_ineq ~ as.factor(frame)*age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata)
mod_donate_polviolence_age <- lm(donate_polviolence ~ as.factor(frame)*age, data = chiledata)
mod_donate_polviolence_age_controls <- lm(donate_polviolence ~ as.factor(frame)*age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata) 
#Interacting treatment with ideology
mod_donate_ineq_ideo <- lm(donate_ineq ~ as.factor(frame)*ideology, data = chiledata)
mod_donate_ineq_ideo_controls <- lm(donate_ineq ~ as.factor(frame)*ideology  + age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata)
mod_donate_polviolence_ideo <- lm(donate_polviolence ~ as.factor(frame)*ideology, data = chiledata)
mod_donate_polviolence_ideo_controls <- lm(donate_polviolence ~ as.factor(frame)*ideology + age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata) 

###DV = words written to delegate
#Main effects
mod_strings <- lm(strings ~ as.factor(frame), data = chiledata)
mod_strings_controls <- lm(strings ~ as.factor(frame) + age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata)
#Interacting treatment with age
mod_strings_age <- lm(strings ~ as.factor(frame)*age, data = chiledata)
mod_strings_age_controls <- lm(strings ~ as.factor(frame)*age + age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata)
#Interacting treatment with ideology
mod_strings_ideo <- lm(strings ~ as.factor(frame)*ideology, data = chiledata)
mod_strings_ideo_controls <- lm(strings ~ as.factor(frame)*ideology + age + white + educ + income + relig + votechoice + urban + change_support, data = chiledata)

#Table C.1: main effects
screenreg(list(mod_support, mod_effective, mod_donate_ineq, mod_donate_polviolence, mod_strings),
       custom.coef.names = c("Intercept","Low Dose Historical Frame","High Dose Historical Frame"),
       custom.model.names = c("Support for Protester Demands","Perceived Protest Effectiveness","Donation to Reduce Ineq.","Donation to Reform Police","Words Written To Delegate")
)

#Table C.2: main effects with controls
screenreg(list(mod_support_controls, mod_effective_controls, mod_donate_ineq_controls, mod_donate_polviolence_controls, mod_strings_controls),
          custom.coef.names = c("Intercept","Low Dose Historical Frame","High Dose Historical Frame","Age","White","Education","Income","Religiosity","Party Preference","Urban","Changed Support for Protesters"),
          custom.model.names = c("Support for Protester Demands","Perceived Protest Effectiveness","Donation to Reduce Ineq.","Donation to Reform Police","Words Written To Delegate")
)

#Table C.3: interactions - ideology
screenreg(list(mod_support_ideo, mod_effective_ideo, mod_donate_ineq_ideo, mod_donate_polviolence_ideo, mod_strings_ideo),
       custom.coef.names = c("Intercept","Low Dose Historical Frame","High Dose Historical Frame","Ideology","Low Dose x Ideology","High Dose x Ideology"),
       custom.model.names = c("Support for Protester Demands","Perceived Protest Effectiveness","Donation to Reduce Ineq.","Donation to Reform Police","Words Written To Delegate")
)

#Table C.4: interactions - ideology with controls
screenreg(list(mod_support_ideo_controls, mod_effective_ideo_controls, mod_donate_ineq_ideo_controls, mod_donate_polviolence_ideo_controls, mod_strings_ideo_controls),
       custom.coef.names = c("Intercept","Low Dose Historical Frame","High Dose Historical Frame","Ideology","Age","White","Education","Income","Religiosity","Party Preference","Urban","Changed Support for Protesters","Low Dose x Ideology","High Dose x Ideology"),
       custom.model.names = c("Support for Protester Demands","Perceived Protest Effectiveness","Donation to Reduce Ineq.","Donation to Reform Police","Words Written To Delegate")
)

#Table C.5: interactions - age
screenreg(list(mod_support_age, mod_effective_age, mod_donate_ineq_age, mod_donate_polviolence_age, mod_strings_age),
          custom.coef.names = c("Intercept","Low Dose Historical Frame","High Dose Historical Frame","Age","Low Dose x Age","High Dose x Age"),
          custom.model.names = c("Support for Protester Demands","Perceived Protest Effectiveness","Donation to Reduce Ineq.","Donation to Reform Police","Words Written To Delegate")
          )

#Table C.6: interactions - age with controls
screenreg(list(mod_support_age_controls, mod_effective_age_controls, mod_donate_ineq_age_controls, mod_donate_polviolence_age_controls, mod_strings_age_controls),
          custom.coef.names = c("Intercept","Low Dose Historical Frame","High Dose Historical Frame","Age","White","Education","Income","Religiosity","Party Preference","Urban","Changed Support for Protesters","Low Dose x Age","High Dose x Age"),
          custom.model.names = c("Support for Protester Demands","Perceived Protest Effectiveness","Donation to Reduce Ineq.","Donation to Reform Police","Words Written To Delegate")
)

#### Appendix D: Text Analysis ####
mod_text_stateviolence_proreform <- glm(text_stateviolence_proreform ~ as.factor(frame), data = chiledata, family = binomial)
mod_text_econ_proreform <- glm(text_econ_proreform ~ as.factor(frame), data = chiledata, family = binomial)

#Figure D.1: Effects of Historical Frames on Content of Letters to a Delegate
coefplot(mod_text_stateviolence_proreform, varnames = names, pch.pts = 16, cex.pts = 1.5, main = "Treatment Effect")
coefplot(mod_text_econ_proreform, add = TRUE, pch.pts = 17, cex.pts = 1.5)
legend("bottomleft", legend = c("Mention Reforming Police Violence","Mention Reforming Economy"), pch = c(16, 17), lty=1, cex=1, box.lty = 0)
